/**
 * Created with CLion.
 * Description: 使用互斥量保护列表
 * User: cyber
 * Date: 2020-09-04
 * Time: 8:58
 */
#include <iostream>
#include <mutex>
#include <algorithm>
#include <list>

using namespace std;

std::list<int> some_list;       // 1
std::mutex some_mutex;          // 2

void add_to_list(int new_value)
{
    std::lock_guard<std::mutex> guard(some_mutex);  // 3
    some_list.push_back(new_value);
}

bool list_contains(int value_to_find)
{
    std::lock_guard<std::mutex> guard(some_mutex); // 4
    //std::lock_guard guard(some_mutex);               // 4   c++17 +
    return std::find(some_list.begin(), some_list.end(), value_to_find) != some_list.end();
}

int main()
{
    int && i=42;
    int j=42;
    //int && k=j;         //Rvalue reference to type 'int' cannot bind to lvalue of type 'int'
    return 0;
}
